package com.iterative.mysql.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.session.mgt.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iterative.common.persistence.Page;
import com.iterative.common.persistence.PropertyFilter;
import com.iterative.common.web.BaseController;
import com.iterative.mysql.entity.MysqlConnect;
import com.iterative.mysql.service.ConnectService;
import com.iterative.system.entity.User;


/**
 * mysql 连接列表
 * @author like
 *
 */
@Controller
@RequestMapping("/mysql/connect")
public class MysqlConnectController extends BaseController{
	@Autowired
	private ConnectService connectService;
//	@Autowired
//	SessionFactory sessionFactory;
	/**
	 * 默认页面
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String list() {
		return "mysql/connectList";
	}
	
	
	/**
	 * 获取所有的mysql连接列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="json")
	@ResponseBody
	public Map<String, Object> getMysqlConnects(HttpServletRequest request ,HttpServletResponse response){
		Page<MysqlConnect> page = getPage(request);
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(request);
		page = connectService.search(page, filters);
		return getEasyUIData(page);
		
	}
	
	
	
	/**
	 * 添加连接跳转
	 * 
	 * @param model
	 */
//	@RequiresPermissions("sys:user:add")
	@RequestMapping(value = "create")
	public String createForm(Model model) {
		User user = new User();
		user.setGender((short)1);
		model.addAttribute("user", user);
		model.addAttribute("action", "create");
		return "system/userForm";
	}
	
	
	
}
